package com.leetcodehot.problems;

import java.util.HashMap;

public class problems3 {
    public int lengthOfLongestSubstring(String s) {
        HashMap<Character, Integer> map = new HashMap<>();
        int n = s.length();
        char[] charArray = s.toCharArray();
        int left = 0;
        int right = 0;
        int res = 0;

        while(right < n) {
            char c = charArray[right];
            while(map.containsKey(c)&&map.get(c) > 0) {
                Integer i = map.get(charArray[left]);
                map.put(charArray[left],i-1);
                left++;
            }
            map.put(c,1);
            res = Math.max(res, right - left + 1);
            right++;
        }
        return res;
    }
}
